<?php
require_once("../config.php");
require_once("../model/DB.php");
require_once("../model/User.php");
require_once("../model/Msg.php");


$msgs = Msg::getMsgs($_SESSION['userid']);
	

		
			
?>
<script>
$(document).ready(function(){
	$("#kid_table").tablesorter( 
		{widthFixed: true, widgets: ['zebra']} 
	).tablesorterPager({container: $("#pager")});
});
</script>
<table id="kid_table" class="tablesorter">
	<thead>
		<tr><td>From</td><td>Content</td><td>Datetime</td><td>Action</td></tr>
	</thead>
	<tbody>
	<tr></tr>
		<?php
		if($msgs){
			
			foreach($msgs as $msg){
				$user = User::getUser('id',$msg['from_id']);
				$to = User::getUser('id',$msg['to_id']);
				?>
				<tr><td><?php if($msg['from_id']!=$_SESSION['userid']){ echo $user[0]['username'];}else{ echo "You to <font color='red'>".$to[0]['username']."</font>";  }?></td><td><?=$msg['content']?></td><td><?=$msg['datetime']?></td><td><?php if($msg['from_id']!=$_SESSION['userid']): ?><a href="javascript:void(0)" onclick="reply(<?=$msg['from_id']?>)">Reply</a><?php endif; ?></td></tr>
				<?php
			}
		}
		?>
	</tbody>
</table>

<div id="pager" class="pager" style="width:800px;margin-left:5px;margin-top:15px">
					<form>
						<img class="first" src="../images/first.png"/>
						<img class="prev" src="../images/prev.png"/>
						<input class="pagedisplay" type="text"/>
						<img class="next" src="../images/next.png"/>
						<img class="last" src="../images/last.png"/>
						<select id="pagesize" class="pagesize">
							 <option value="10" >10</option>
							 <option value="15" >15</option>
							
						</select>
					</form>
</div>